package core.proto.vis.action;

import java.awt.Point;
import java.awt.geom.Rectangle2D;

import prefuse.Display;
import prefuse.Visualization;
import prefuse.action.GroupAction;
import prefuse.util.GraphicsLib;
import prefuse.util.display.DisplayLib;

public class ZoomToFitAction extends GroupAction {

	Display display;
	public ZoomToFitAction (Display display) {
		this.display = display;
	}
	
	public void run(double frac) {
		long duration = 0;
		int margin = 50;

//		if (! display.isTranformInProgress() ){
			Visualization vis = getVisualization();
			//		Rectangle2D bounds = vis.getBounds( VISIBLE );
			Rectangle2D bounds = vis.getBounds( Visualization.ALL_ITEMS );
//			Point center = new Point(
//					display.getVisibleRect().x + display.getVisibleRect().width / 2, 
//					display.getVisibleRect().y + display.getVisibleRect().height / 2);
			GraphicsLib.expand( bounds, margin + ( int ) ( 1 / display.getScale() ) );
			DisplayLib.fitViewToBounds( display, bounds, duration );
//		}

	}
}
